X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/38c7d3f9eb7d63937c6654ff5dd6046ce02dd59c..4fc09567c557a1110180940cca40fd7144921026:/Super%20Polarity/Actors/MainShip.cs diff --git a/Super Polarity/Actors/MainShip.cs b/Super Polarity/Actors/MainShip.cs deleted file mode 100644 index 1f4f22a..0000000 --- a/Super Polarity/Actors/MainShip.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; - -namespace SuperPolarity -{ - class MainShip : Ship - { - - public static Color BlueColor; - public static Color RedColor; - - ParticleEngine particleEngine; - - protected bool Shooting; - protected int ShotCooldown; - - public MainShip(Game newGame) : base(newGame) {} - - ~MainShip() - { - particleEngine = null; - } - - public override void Initialize(Texture2D texture, Vector2 position) - { - base.Initialize(texture, position); - - MainShip.BlueColor = new Color(230, 244, 249); - MainShip.RedColor = new Color(255, 234, 241); - - InitParticleEngine(); - SetPolarity(Polarity.Positive); - - ShotCooldown = 50; - - BindInput(); - } - - void InitParticleEngine() - { - particleEngine = ParticleEffectFactory.CreatePolarCircle(Position); - } - - void BindInput() - { - InputController.Bind("moveX", HandleHorizontalMovement); - InputController.Bind("moveY", HandleVerticalMovement); - InputController.Bind("changePolarity", HandleChangePolarity); - InputController.Bind("shoot", HandleShot); - } - - protected void HandleShot(float value) - { - Children.Add(ActorFactory.CreateBullet(Position, Angle)); - Shooting = true; - Timer t = new Timer(new TimerCallback(UnlockShot)); - t.Change(ShotCooldown, Timeout.Infinite); - } - - protected void UnlockShot(object state) - { - InputController.Unlock("shoot"); - } - - protected void HandleChangePolarity(float value) - { - SwitchPolarity(); - } - - public void HandleHorizontalMovement(float value) - { - Acceleration.X = value * AccelerationRate; - - if (value > 0.1 && Velocity.X < 0 || value < 0.1 && Velocity.X > 0) - { - Acceleration.X *= 2; - } - - if (value > 0.1 && Velocity.Y < 0 || value < 0.1 && Velocity.Y > 0) - { - Acceleration.Y *= 2; - } - } - - public void HandleVerticalMovement(float value) - { - Acceleration.Y = value * AccelerationRate; - } - - public override void SwitchPolarity() - { - base.SwitchPolarity(); - SwitchParticleEngine(CurrentPolarity); - } - - public override void SetPolarity(Polarity newPolarity) - { - base.SetPolarity(newPolarity); - SwitchParticleEngine(newPolarity); - } - - protected void SwitchParticleEngine(Polarity polarity) - { - if (polarity == Polarity.Positive) - { - particleEngine.Color = MainShip.RedColor; - } - else if (polarity == Polarity.Negative) - { - particleEngine.Color = MainShip.BlueColor; - } - else - { - particleEngine.Color = Color.Gray; - } - } - - public override void Update(GameTime gameTime) - { - base.Update(gameTime); - particleEngine.EmitterLocation = Position; - particleEngine.Update(); - ConstrainToEdges(); - Shooting = false; - } - - public override void Move(GameTime gameTime) - { - base.Move(gameTime); - - if (Shooting) - { - if (Velocity.X > ActVelocity) - { - Velocity.X = ActVelocity; - } - - if (Velocity.X < -ActVelocity) - { - Velocity.X = -ActVelocity; - } - - if (Velocity.Y > ActVelocity) - { - Velocity.Y = ActVelocity; - } - - if (Velocity.Y < -ActVelocity) - { - Velocity.Y = -ActVelocity; - } - } - } - - public override void Magnetize(Ship ship, float distance, float angle) - { - } - - protected void ConstrainToEdges() - { - if (Position.X < 0) - { - Position.X = 0; - - if (Velocity.X < 0) - { - Velocity.X = 0; - } - } - if (Position.X > game.GraphicsDevice.Viewport.Width) - { - Position.X = game.GraphicsDevice.Viewport.Width; - - if (Velocity.X > 0) - { - Velocity.X = 0; - } - } - if (Position.Y < 0) - { - Position.Y = 0; - - if (Velocity.Y < 0) - { - Velocity.Y = 0; - } - } - if (Position.Y > game.GraphicsDevice.Viewport.Height) - { - Position.Y = game.GraphicsDevice.Viewport.Height; - - if (Velocity.Y < 0) - { - Velocity.Y = 0; - } - } - } - - public override void Draw(SpriteBatch spriteBatch) - { - particleEngine.Draw(spriteBatch); - base.Draw(spriteBatch); - } - } -}